<?php


abstract class Message {
	protected $value;
	public function __construct($value){ $this->value = strval($value); }
	public function __toString(){ return $this->AsString(); }
	public final function AsString(){ return $this->value; }

	const INFO = 0;
	const SUCCESS = 1;
	const QUESTION = 2;
	const WARNING = 3;
	const ERROR = 4;

	public abstract function GetIconName();
	public abstract function GetSeverity();
	public abstract function GetBackgroundColor();
	public abstract function GetBorderColor();

	public final function GetIconSrc($size){ return $this->GetIconName().$size.'.gif'; }
	public final function GetIcon($size) { return new Icon($this->GetIconName(),$size); }
	public final function GetIconScr16(){ return $this->GetIconSrc(16); }
	public final function GetIconScr32(){ return $this->GetIconSrc(32); }
	public final function GetIconScr48(){ return $this->GetIconSrc(48); }
	public final function GetIcon16() { return $this->GetIcon(16); }
	public final function GetIcon32() { return $this->GetIcon(32); }
	public final function GetIcon48() { return $this->GetIcon(48); }

	public static function Cast($value){
		if ($value instanceof Message)
			return $value;

		if ($value instanceof MessageException)
			return $value->AsMessage();

		if ($value instanceof Exception)
			return new ErrorMessage($value->getMessage());

		if ($value instanceof Validator)
			return $value->AsMessage();

		if (is_array($value))
			return new MultiMessage($value);

		return new ErrorMessage(strval($value));
	}

}

?>
